package in.iqing.control.api.volley;

import android.content.pm.PackageInfo;
import android.os.Build;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;

import java.util.HashMap;
import java.util.Map;

import in.iqing.App;
import in.iqing.app.R;

/**
 * Created by ZuoShu on 15/7/11.
 */
public class QingAuthedRequest extends ExtendStringRequest {
    public QingAuthedRequest(String userAgent, int method, int timeout, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(userAgent, method, timeout, url, listener, errorListener);
    }

    public QingAuthedRequest(String userAgent, int method, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(userAgent, method, url, listener, errorListener);
    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> headers = super.getHeaders();
        if (headers == null) {
            headers = new HashMap<>();
        }
        try {
            PackageInfo info = App.getInstance().getPackageManager().getPackageInfo(App.getInstance().getPackageName(), 0);
            headers.put("AppVersion", info.versionName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        headers.put("System", "android");
        headers.put("Version", android.os.Build.MODEL + ","
                + Build.VERSION.SDK_INT + ","
                + android.os.Build.VERSION.RELEASE);
        headers.put("GUID", android.os.Build.SERIAL);
        return headers;
    }
}
